﻿using CIS.Client.Modules.Operation.Models;
using Prism.Commands;
using Prism.Mvvm;
using Prism.Regions;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static CIS.Client.Modules.Operation.Models.PPIDModel;

namespace CIS.Client.Modules.Operation.ViewModels
{
    public class PPIDViewModel : BindableBase
    {
        private readonly IRegionManager _regionManager;

        public PPIDViewModel(IRegionManager regionManager)
        {
            this._regionManager = regionManager;
            var parentName = new string[5] { "张", "王", "李", "赵", "刘" };
            var province = new string[5] { "河南", "江苏", "河北", "湖北", "福建" };
            PPIDList = new ObservableCollection<PPIDModel>();
            for (int i = 0; i < 50; i++)
            {
                var student = new PPIDModel()
                {
                    Id = Guid.NewGuid().ToString(),
                    Name = parentName[(i % 4)] + i.ToString().PadLeft(2, 'A'),
                    Age = 20 + (i % 5),
                    Gender = i % 2 == 0 ? "男" : "女",
                    Addr = province[(i % 4)]
                };
                this.PPIDList.Add(student);
            }
        }

        private ObservableCollection<PPIDModel> ppidList;

        public ObservableCollection<PPIDModel> PPIDList
        {
            get { return ppidList; }
            set { ppidList = value; }
        }





        #region ContentControl 相关属性
        /// <summary>
        /// TabItem 显示名称
        /// </summary>
        public string? PageTitle { get; set; } = "PPID设置";

        /// <summary>
        /// 导航属性
        /// </summary>
        public string? NavUri { get; set; } = "PPIDView";

        /// <summary>
        /// 是否可关闭
        /// </summary>
        public bool IsCanClose { get; set; } = true;

        /// <summary>
        /// TabControl 关闭按钮命令
        /// </summary>
        public DelegateCommand<string>? CloseCommand
        {
            get
            {
                return new DelegateCommand<string>(CloseFunction);
            }
        }

        /// <summary>
        /// TabControl 关闭按钮执行操作
        /// </summary>
        /// <param name="navUri"></param>
        private void CloseFunction(string navUri)
        {
            var removeView = _regionManager.Regions["MainRegion"].Views.FirstOrDefault(v => v.GetType().Name == navUri);
            if (removeView != null)
            {
                _regionManager.Regions["MainRegion"].Remove(removeView);
            }
        }
        #endregion

    }
}
